package cn.cloudmenu.android;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

import android.content.Context;

public class ServerAccessor {
	
	//private
	public static JSONObject access(Context context, HttpUriRequest request) throws Exception {
		// 发送请求
		HttpResponse httpResponse = new DefaultHttpClient().execute(request);
		// 得到应答的字符串，这也是 JSON 格式保存的数据
		String retSrc = EntityUtils.toString(httpResponse.getEntity());
		
		// 生成 JSON 对象
		JSONObject jSONObject = new JSONObject(retSrc);
		if(jSONObject.has("needPay")) throw new NeedPayException();
		//{
			//Intent intent = new Intent(context, ShowNotify.class);
			//intent.putExtra("messagetype", 1);//1为url type，其它为文本
			//intent.putExtra("message", CodeUtils.encode("http://www.5iwords.com/api/needPay.html"));
			//context.startActivity(intent);
			//throw new NeedPayException();
		//}
		return jSONObject;
	}

}
